
<style lang="less">
  .page__wrapper {
    width: 100%;
    height: 100%;
  }
</style>
<template>
  <div class="page__wrapper">
    <simple-table :table-column="tableColumn" show-expand :table-data="tableData" :pageable="false">
      <template slot-scope="scope" slot="expandRow">
        <simple-table :table-column="tableColumn" :table-data="scope.row" :show-header="false" :pageable="false">
          <template slot="companyname" slot-scope="scope">
            <span>{{scope.row.companyname}}</span>
          </template>
        </simple-table>
      </template>
      <template slot="companyname" slot-scope="scope">
        <span style="font-weight: bolder;">{{scope.row.companyname}}</span>
      </template>
      <template slot="searchSection">
        <simple-form v-model="searchModel" :form-field="searchFormField">
          <template slot="tableOperation">
            <el-button @click="handleDataSearch">{{$t('operation.search')}}</el-button>
          </template>
        </simple-form>
      </template>
    </simple-table>
  </div>
</template>
<script>
import Axios from 'axios'
const BASEURL = {
  list: `/web/report/ajax.html?sys_method=GetList&sys_objName=V_Report_Unlisted_Reform`,
  getInitConfig: '/Web/SysAdmin/ajax.html?sys_method=GetInitConfig',
  getCombobox: '/Web/SysAdmin/ajax.html?sys_method=GetCombobox'
}
export default {
  name: 'unlisted_reform_report',
  components: {},
  data () {
    return {
      searchModel: {},
      /** 表格数据 */
      tableData: [],

      actionList: [],
      sys_mid: '',
      orgList: []
    }
  },
  filters: {
    companynameFilter (value, orgList) {
      let company = orgList.find(item => {
        return item.value === value
      })
      return company ? company.text : ''
    }
  },
  computed: {
    searchFormField () {
      return [
        { prop: 'companyname', label: this.$t('balance_factory.companyname'), type: 'Select', component: { clearable: true, optionList: this.orgList } },
        { prop: 'uploadyear', label: this.$t('balance_factory.uploadyear'), type: 'Datepicker', component: { clearable: true, type: 'year', valueFormat: 'yyyy' } },
        { prop: 'uploadquarter', label: this.$t('balance_factory.uploadquarter'), type: 'Select', component: { clearable: true, optionList: this.$getDictList('季度') } },
        { slotName: 'tableOperation', col: { span: 6, style: { textAlign: 'right' } }, labelWidth: '0' }
      ]
    },
    tableColumn () {
      return [
        { prop: 'companyname', label: '业务及三级单位', width: 180, slotName: 'companyname', fixed: 'left' },
        { prop: 'reformmethod', label: '改革方式', width: 100 },
        // {
        //   label: '单位数量',
        //   children: [
        //     { prop: 'uploadquarter', label: '年初数', width: 70, slotName: 'uploadquarter' },
        //     { prop: 'xxx', label: '期末数', width: 70 }
        //   ]
        // },
        { prop: 'totalprofit2015', label: '2015年利润总额', width: 110 },
        { prop: 'totalprofityearandcostmining', label: '本年累计利润总额', width: 120 },
        {
          label: '非经营性费用',
          children: [
            { prop: 'subtotalnonoperatingcost', label: '小计', width: 70 },
            { prop: 'repairreconstructioncost', label: '“三供一业”维修改造费用', width: 160 },
            { prop: 'assetimpairmentloss', label: '资产减值及处置损失', width: 130 },
            { prop: 'resettlementcost', label: '人员分流安置费用', width: 120 }
          ]
        },
        { prop: 'reformmeasuresprogress', label: '改革措施与进展', width: 110 },
        { prop: 'existingproblem', label: '存在问题', minWidth: 120 }
      ]
    },
    fixedRows () {
      return [{
        companyname: '(一)主业生产运行保障业务',
        id: '1',
        children: [
          { companyname: '1.井下作业', key: 'type1' },
          { companyname: '2.检维修' },
          { companyname: '3.供水' },
          { companyname: '4.供发电' },
          { companyname: '5.物资供应' },
          { companyname: '6.通讯' },
          { companyname: '7.科研' },
          { companyname: '8.油气合作开发' }
        ]
      }, {
        companyname: '(二)专业化服务业务',
        id: '2',
        children: [
          { companyname: '1.工程建设' },
          { companyname: '2.工程技术' },
          { companyname: '3.装备制造' },
          { companyname: '4.运输' }
        ]
      }, {
        companyname: '(三)宾馆办事处',
        id: '3',
        children: []
      }, {
        companyname: '(四)培训院校',
        id: '4',
        children: []
      }, {
        companyname: '(五)矿区',
        id: '5',
        children: []
      }, {
        companyname: '(六)其他',
        id: '6',
        children: [
          { companyname: '1.房地产' },
          { companyname: '2.化工' },
          { companyname: '3.贸易' },
          { companyname: '4.监理' },
          { companyname: '5.本部机关' },
          { companyname: '6.控股' },
          { companyname: '7.其他' }
        ]
      }, {
        companyname: '(七)抵消',
        id: '7',
        children: []
      }]
    }
  },
  /**
   * 注入到子组件
   */
  provide () {
    return { handleDataSearch: this.handleDataSearch }
  },
  methods: {
    handleDataSearch () {
      let params = Object.assign({}, this.tablePageInfo, { sys_mid: this.sys_mid }, { sys_search: this.searchModel })

      let loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      this.$axios
        .post(BASEURL.list, params)
        .then(resp => {
          this.tableData = resp.rows
          this.tableDataTotalCount = resp.total
        })
        .finally(() => {
          loadingFlag.close()
        })
    },
    handleInitData () {
      let configLoadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      this.$axios.post(BASEURL.getInitConfig)
        .then(resp => {
          this.actionList = resp.actionKeys.split(',')
          this.sys_mid = resp.mid

          /** 设置列表及涉及主数据请求参数 */
          let params = Object.assign({}, this.tablePageInfo, { sys_mid: resp.mid })
          let comboParams = { sys_json: JSON.stringify([{ ObjName: 'C_SYS_Org' }]) }
          let loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })

          Axios.all([
            this.$axios.post(BASEURL.getCombobox, comboParams),
            this.$axios.post(BASEURL.list, params)
          ])
            .then(Axios.spread((comboData, pageData) => {
              this.orgList = comboData.C_SYS_Org

              this.formatTableData(pageData.rows)
            }))
            .finally(() => {
              loadingFlag.close()
            })
        })
        .finally(() => {
          configLoadingFlag.close()
        })
    },

    // 将请求数据格式化成前端显示的格式
    formatTableData (tableData) {
      this.$set(this, 'tableData', this.fixedRows)
    }
  },
  mounted () {
    this.handleInitData()
  }
}
</script>
